package com.smedi.ismedi.inmail.api.feign;

import com.smedi.ismedi.inmail.api.dto.request.*;
import com.smedi.ismedi.inmail.api.dto.response.ProcessTaskResponse;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.io.IOException;
import java.util.List;

/**
 * @author u
 */
@FeignClient(name = "ismedi-inmail")
@Api(value = "流程", tags = {"流程"})
@RequestMapping(value = "/api")
public interface RemoteProcessFeignApi {
    /**
     * 部署 流程定义
     *
     * @param processPerformFile 流程 部署 请求
     * @return ResponseData<ProcessTaskResponse>
     */
    @ApiOperation(httpMethod = "POST", value = "部署 流程定义")
    @PostMapping(value = "/v1/process-definition/deploy", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseData<Boolean> deployProcessDefinition(@ApiParam(value = "file", required = true) @RequestPart(value = "file") MultipartFile processPerformFile) throws IOException;

    /**
     * 启动/重启 流程实例
     *
     * @param processInstanceStartRequest 流程实例 启动 请求
     * @return ResponseData<ProcessTaskResponse> 当前正在处理的任务
     */
    @ApiOperation(httpMethod = "POST", value = "启动/重启 流程实例")
    @PostMapping(value = "/v1/process-instance/start")
    ResponseData<ProcessTaskResponse> startProcessInstance(@Valid @RequestBody ProcessInstanceStartRequest processInstanceStartRequest);

    /**
     * 完成 流程任务
     *
     * @param processTaskCompleteRequest 流程任务 完成 请求
     * @return ResponseData<ProcessTaskResponse> 当前正在处理的任务
     */
    @ApiOperation(httpMethod = "POST", value = "完成 流程任务(仅支持串行网关)")
    @PostMapping(value = "/v1/process-task/complete")
    ResponseData<ProcessTaskResponse> completeProcessTask(@Valid @RequestBody ProcessTaskCompleteRequest processTaskCompleteRequest);

    /**
     * 完成 流程任务
     *
     * @param processTaskCompleteRequest 流程任务 完成 请求
     * @return ResponseData<ProcessTaskResponse> 当前正在处理的任务
     */
    @ApiOperation(httpMethod = "POST", value = "完成 流程任务")
    @PostMapping(value = "/v2/process-task/complete")
    ResponseData<List<ProcessTaskResponse>> completeProcessTask2(@Valid @RequestBody ProcessTaskCompleteRequest processTaskCompleteRequest);

    /**
     * 获取 历史流程任务 列表
     *
     * @param processTaskListRequest 历史流程任务 列表 请求
     * @return ResponseData<ProcessTaskResponse> 完成了的和未完成的任务
     */
    @ApiOperation(httpMethod = "POST", value = "获取 历史流程任务 列表")
    @PostMapping(value = "/v1/process-task/list")
    ResponseData<List<ProcessTaskResponse>> getProcessTaskList(@Valid @RequestBody ProcessTaskListRequest processTaskListRequest);

    /**
     * 关闭 流程实例
     *
     * @param processInstanceCloseRequest 流程实例 关闭 请求
     * @return ResponseData<Boolean>
     */
    @ApiOperation(httpMethod = "POST", value = "流程实例 关闭 列表")
    @PostMapping(value = "/v1/process-instance/close")
    ResponseData<Boolean> closeProcessInstance(@Valid @RequestBody ProcessInstanceCloseRequest processInstanceCloseRequest);

    /**
     * 撤回 流程任务
     *
     * @param processTaskCancelRequest 流程任务 撤回 请求
     * @return ResponseData<ProcessTaskResponse> 当前正在处理的任务
     */
    @ApiOperation(httpMethod = "POST", value = "撤回 流程任务(仅支持串行网关)")
    @PostMapping(value = "/v1/process-task/back")
    ResponseData<ProcessTaskResponse> cancelProcessTask(@Valid @RequestBody ProcessTaskCancelRequest processTaskCancelRequest);

    /**
     * 撤回 流程任务
     *
     * @param processTaskCancelRequest 流程任务 撤回 请求
     * @return ResponseData<ProcessTaskResponse> 当前正在处理的任务
     */
    @ApiOperation(httpMethod = "POST", value = "撤回 流程任务")
    @PostMapping(value = "/v2/process-task/back")
    ResponseData<List<ProcessTaskResponse>> cancelProcessTask2(@Valid @RequestBody ProcessTaskCancelRequest processTaskCancelRequest);
}
